<%@page import="com.zretc.news.entity.NewsType"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title>添加新闻</title>

<!--1. Bootstrap core CSS -->
<link href="dist/css/bootstrap.min.css" rel="stylesheet">



<!--2. Custom styles for this template -->
<link href="css/dashboard.css" rel="stylesheet">

</head>

<body>
	<jsp:include page="nav.html"></jsp:include>
	<div class="container-fluid">
		<div class="row">
			<div class="col-sm-3 col-md-2 sidebar">
				<ul class="nav nav-sidebar">
					<li><a href="NewsTypeServlet">新闻类型<span class="sr-only">(current)</span></a></li>
					<li><a href="addtype.jsp">新增类型</a></li>
					<li><a href="addusers.jsp">新增用户</a></li>
					<li><a href="NewsTypeServlet?op=queryByPage">新闻类型表(分页) </a></li>
					<li class="active"><a href="addnews.jsp">新增新闻</a></li>
				</ul>

			</div>
			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
				<h2 class="sub-header">新增新闻</h2>
				<p>关于发布的时间，作者是谁？</p>
				<div class="row clearfix">
					<div class="col-md-8 column">
						<%=request.getAttribute("msg") == null ? "" : request.getAttribute("msg")%>
						<!-- 前端的校验，大家要记得完成一下  onsubmit="return fun()"-->
						<form class="form-horizontal" role="form" action="NewsServlet"
							method="post">
							<div class="form-group">
								<label for="inputEmail3" class="col-sm-2 control-label">新闻标题</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="newstitle"
										name="newstitle" required="required" />
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">新闻内容</label>
								<div class="col-sm-10">
									<textarea class="form-control" id="newscontent"
										name="newscontent"></textarea>
									<!-- 新闻内容 可以用文本域?但是更优的选择是 -- "富文本框" -->
									<!-- 	<input type="text" class="form-control" id="newscontent" name="newscontent" required="required"/> -->
								</div>
							</div>

							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">新闻类型</label>
								<div class="col-sm-10">
									<select class="form-control" id="newstype" name="newstype">

									</select>

								</div>
							</div>
							<input type="hidden" name="op" value="add">
							<!-- 处理重复提交操作的一个 token 令牌，表单提交，令牌也提交 -->
							<%
							   //重复提交 I. 在session范围内产生一个token的值。
								session.setAttribute("token", System.nanoTime() + "");
							%>
							<!-- 重复提交 II 将token通过隐藏域传递给servlet -->
							<input type="hidden" name="token" value="${sessionScope.token}">

							<div class="form-group">
								<div class="col-sm-offset-2 col-sm-10">
									<button type="submit" class="btn btn-default">增加</button>
								</div>
							</div>
						</form>
					</div>
					<div class="col-md-4 column"></div>
				</div>



			</div>
		</div>
	</div>

	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!--3 - js/jquery-2.0.3.js -->
	<script src="js/jquery-2.0.3.js"></script>
	<!--4 - ootstrap.min.js -->
	<script src="dist/js/bootstrap.min.js"></script>

	<script>
		$(function() {

			//得到一个对象，或者多个对象，将对象显示层中
			$.get("NewsTypeServlet?op=ajaxReq", function(data) {
				//测试控制台没有问题
				//不用JSON.parse可以不?
				// console.log(data);
				//遍历 jQuery的遍历怎么走吗？
				$.each(data, function(index, nt) {
					// console.log(index+","+nt.id+","+nt.newstype);
					$("#newstype").append(
							"<option value="+nt.typeid+">" + nt.typename
									+ "</option>");
				});
			});
		});
	</script>

</body>
</html>
